package com.zj.fx.service.month;

import java.util.List;
import java.util.Arrays;

import com.zj.fx.mapper.month.MonthEvaluationMapper;
import com.zj.fx.model.month.MonthEvaluation;
import com.zj.fx.model.month.MonthEvaluationExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.zj.fx.common.base.BaseService;
import com.zj.fx.common.support.ConvertUtil;
import com.zj.fx.model.custom.Tablepar;
import com.zj.fx.util.SnowflakeIdWorker;
import com.zj.fx.util.StringUtils;

/**
 * 月度评价任务台账 MonthEvaluationService
 *
 * @author SQL_自动生成
 * @Title: MonthEvaluationService.java 
 * @Package com.zj.fx.service 
 * @email ${email}
 * @date 2023-06-09 14:44:21  
 **/
@Service
public class MonthEvaluationService implements BaseService<MonthEvaluation, MonthEvaluationExample> {
    @Autowired
    private MonthEvaluationMapper monthEvaluationMapper;


    /**
     * 分页查询
     *
     * @param
     * @param
     * @return
     */
    public PageInfo<MonthEvaluation> list(Tablepar tablepar, MonthEvaluation monthEvaluation) {
        MonthEvaluationExample testExample = new MonthEvaluationExample();
        //搜索
        if (StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
            testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
        } else {//大搜索
            testExample.createCriteria().andLikeQuery(monthEvaluation);
        }
        //表格排序
        if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
        	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
        }else{
        	testExample.setOrderByClause("create_time DESC");
        }
        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        List<MonthEvaluation> list = monthEvaluationMapper.selectByExample(testExample);
        PageInfo<MonthEvaluation> pageInfo = new PageInfo<MonthEvaluation>(list);
        return pageInfo;
    }

    @Override
    public int deleteByPrimaryKey(String ids) {

        List<String> lista = ConvertUtil.toListStrArray(ids);
        MonthEvaluationExample example = new MonthEvaluationExample();
        example.createCriteria().andIdIn(lista);
        return monthEvaluationMapper.deleteByExample(example);


    }


    @Override
    public MonthEvaluation selectByPrimaryKey(String id) {

        return monthEvaluationMapper.selectByPrimaryKey(id);

    }


    @Override
    public int updateByPrimaryKeySelective(MonthEvaluation record) {
        return monthEvaluationMapper.updateByPrimaryKeySelective(record);
    }


    /**
     * 添加
     */
    @Override
    public int insertSelective(MonthEvaluation record) {

        //添加雪花主键id
        record.setId(SnowflakeIdWorker.getUUID());


        return monthEvaluationMapper.insertSelective(record);
    }


    @Override
    public int updateByExampleSelective(MonthEvaluation record, MonthEvaluationExample example) {

        return monthEvaluationMapper.updateByExampleSelective(record, example);
    }


    @Override
    public int updateByExample(MonthEvaluation record, MonthEvaluationExample example) {

        return monthEvaluationMapper.updateByExample(record, example);
    }

    @Override
    public List<MonthEvaluation> selectByExample(MonthEvaluationExample example) {

        return monthEvaluationMapper.selectByExample(example);
    }


    @Override
    public long countByExample(MonthEvaluationExample example) {

        return monthEvaluationMapper.countByExample(example);
    }


    @Override
    public int deleteByExample(MonthEvaluationExample example) {

        return monthEvaluationMapper.deleteByExample(example);
    }


    public int checkNameUnique(MonthEvaluation monthEvaluation) {
        MonthEvaluationExample monthEvaluationExample = new MonthEvaluationExample();
        MonthEvaluationExample.Criteria criteria = monthEvaluationExample.createCriteria();
        criteria.andEvaluationDateEqualTo(monthEvaluation.getEvaluationDate());
        List<MonthEvaluation> monthEvaluations = monthEvaluationMapper.selectByExample(monthEvaluationExample);
        return  monthEvaluations.size();
    }

    /**
     * 添加并返回主键ID
     */
    public String insertSelectiveReturnId(MonthEvaluation record) {
        //添加雪花主键id
        record.setId(SnowflakeIdWorker.getUUID());
        monthEvaluationMapper.insertSelective(record);
        return record.getId();
    }

    public MonthEvaluation getNewestMonth() {
        return monthEvaluationMapper.getNewestMonth();
    }
}
